/**
 *  last update : 2015.04.24
 *  name : PostViewer Modal
 *  author : Faeple.com
 */

var loadComment_cnt = 0;
var commentIndex = 0;
var post_idx = 0;
var comment_cnt = 0;
var post_memberIdx = 0;
var likeMemberIndex = 0;

$(document).on("click", "#post-modal-close", function(){
	history.back();
});
$(document).on("click", "#post-modal", function(e){
	if(e.target==this){
		history.back();
	}
});
$(document).on("click", ".comment-edit-btn", function(e){
	$(this).next().next().css({"top":$(this).offset().top+27,"left":$(this).offset().left-62});
});

$(document).on("click", "#inputComment", function(){
	if(member_idx == ""){
		$("#login-dialog").modal("show");
	}else{
		$.ajax({
			type : "get"
		    , url : "/getTagUserList"
		    , dataType : "json"
		    , success : function(response) {
		    	var users = [];
		    	for(var i=0;i<response.length;i++){
		    		users.push({"name":response[i].name,"username":response[i].id,"image":"/resources/upload/profile/thumbnail/"+response[i].profileImage});
		    	}
		    	$("#inputComment").mention({
	    			sensitive: true,
					users: users
				});
		    }
		});
	}
});

	
$(document).on("click", "#image-list > li", function(){
	$("#image-list > li").each(function(){
		$(this).removeClass("active");
	});
	mySwipe.slide($(this).index(), 300);
	$(this).addClass("active");
});
	
function getMoreComment(el){
	commentIndex += 8;
	var data = "post_idx="+post_idx+"&index="+commentIndex+"&order=createdate";
	$.ajax({
		type : "post"
	    , url : "/getCommentWithPost"
	   	, data : data
	    , dataType : "json"
	    , timeout : 5000
	    , error : function() {
	    	$("#item-commentList").append("<div style='text-align:center;'><i class='glyphicon glyphicon-remove' style='color:#BF0000;'></i>&nbsp;댓글을 가져올 수 없습니다.</div>");
	    }
	    , success : function(data) {
	    	var comm = "";
	    	if(data != ""){
	    		for(var i=0;i<data.length;i++){
	    			comm += "<div class='comment' data-idx='"+data[i].idx+"' data-memidx='"+data[i].member_idx+"'><div class='profile-img'><a href='/"+data[i].member_id+"' target='_blank'><img src='/resources/upload/profile/thumbnail/"+data[i].profileImage+"'></a></div><div class='comment-info'><span class='comment-author'><a href='/"+data[i].member_id+"' target='_blank' class='userLink' style='font-weight:bold;'>"+data[i].author+"</a></span><span class='comment-time'>"+timeleft(data[i].create_date)+"</span><div class='comment-content' data-content='"+data[i].content+"'>"+data[i].content.parseUsername().parseURL().parseEmoji()+"</div></div>";
	    			if(member_idx == data[i].member_idx){
	    				comm += "<div class='comment-edit dropdown' title='수정 및 삭제' data-toggle='tooltip'><i class='glyphicon glyphicon-pencil comment-edit-btn' data-toggle='dropdown'></i><input type='hidden' id='editCommentIdx'><ul class='dropdown-menu cmt-dropdown'><li onclick='comment_udpdate_init(this, "+data[i].idx+")'>수정하기</li><li onclick='comment_del("+data[i].idx+")' style='color:#cd2f2f;'>삭제하기</li></ul></div></div>";
	    			}else{
	    				comm += "<div class='comment-report'><i class='fa fa-flag' data-toggle='tooltip' title='신고하기' onclick='report("+data[i].idx+", \"comment\" )' /></div><div class='comment-reply'><i class='fa fa-reply' data-toggle='tooltip' title='답변하기' onclick='commentReply(\""+data[i].member_id+"\")' /></div></div>";
	    			}
	    			loadComment_cnt++;
		    	}
	    		if(loadComment_cnt == comment_cnt){
	    			$(el).hide();
	    		}
	    		$("#item-commentList").prepend(comm);
	    	}else{
	    		$(el).hide();
	    	}
	    }
	    , beforeSend: function() {
	    	$(el).children("i").show();
	    }
	    , complete: function() {
	    	$(el).children("i").hide();
	    }
	});
}
	
String.prototype.parseTagUser = function() {
	hashpattern = /(@[A-Za-z0-9-_]+)/g;
	return this.match(hashpattern);
};

String.prototype.parseHashtag = function() {
	return this.replace(/[#]+[A-Za-z0-9가-힣_]+/g, function(t) {
		return "<a href='/hashtag/"+t.substr(1)+"' class='hashtag' target='_blank'>"+t+"</a>";
	});
};

function submitComment(obj, refer_img, refer_url){
	var tagUser = obj.value.parseTagUser();
	if(tagUser != null) tagUser = tagUser.toString();
	var data = "post_idx="+post_idx+"&content="+obj.value+"&refer_idx="+post_idx+"&author_idx="+post_memberIdx+"&refer_img="+refer_img+"&refer_url="+refer_url+"&tagUser="+tagUser+"&comment-type="+$("#comment-type").val();
	if(!member_idx){
		alertShow("danger","로그인이 필요합니다", 2000);
	}else{
		if(obj.value != ""){
			$.ajax({
  				type : "post"
  			    , url : "/submitComment"
  			    , data : data
  			    , dataType : "text"
  			    , timeout : 5000
  			  	, error : function() {
  			  		alertShow("danger","다시 시도해주세요", 2000);
  			    }
  			    , success : function(response) {
  			    	if(response != "role" && response != "tag"){
  			    		$("#item-commentList").append("<div class='comment' data-idx='"+response+"' data-memidx='"+member_idx+"'><div class='profile-img'><a href='/"+member_id+"' target='_blank'><img src='/resources/upload/profile/thumbnail/"+member_profile+"'></a></div><div class='comment-info'><span class='comment-author'><a href='/"+member_id+"' target='_blank' class='userLink' style='font-weight:bold;'>"+member_name+"</a></span><span class='comment-time'>방금전</span><div class='comment-content' data-content='"+$(obj).val()+"'>"+$(obj).val().parseUsername().parseURL()+"</div></div><div class='comment-edit dropdown' title='수정 및 삭제' data-toggle='tooltip'><i class='glyphicon glyphicon-pencil comment-edit-btn' data-toggle='dropdown'></i><input type='hidden' id='editCommentIdx'><ul class='dropdown-menu cmt-dropdown'><li onclick='comment_udpdate_init(this, "+response+")'>수정하기</li><li onclick='comment_del("+response+")' style='color:#cd2f2f;'>삭제하기</li></ul></div></div>");
  			    		$(obj).val("");
  			    		alertShow("success","댓글이 작성되었습니다", 2000);
  			    		$("#comment-cnt").html(parseInt($("#comment-cnt").html())+1);
  			    		$("#comment-type").val("default");
  			    	}else if(response == "role"){
  			    		alertShow("danger","로그인이 필요합니다", 2000);
  			    	}else if(response == "tag"){
  			    		alertShow("info","상대방 태그가 잘못되었습니다<br>아이디를 확인해 주세요", 6000);
  			    	}
  			    }
  			});
		}else{
			$(obj).val("");
			alertShow("info","내용을 입력해 주세요", 2000);
		}
	}
}
	
function comment_del(idx){
	if(confirm('정말로 삭제할까요?')){
		$.ajax({
			type : "post"
		    , url : "/commentDelete?comment_idx="+idx
		    , dataType : "text"
		    , timeout : 5000
		    , error : function() {
		    	alertShow("danger","다시 시도해주세요", 2000);
		    }
		    , success : function(response) {
		    	if(response == "execute"){
		    		$("#item-commentList > .comment").each(function(){
		    			if($(this).data("idx") == idx){
		    				$(this).remove();
		    				$("#itemEditMenu").hide();
		    			}
   			    	});
		    		alertShow("success","삭제되었습니다", 2000);
		    		$("#comment-cnt").html(parseInt($("#comment-cnt").html())-1);
		    	}else if(response == "fail"){
		    		alertShow("danger","다시 시도해주세요", 2000);
		    	}else{
		    		location.href='/warning.jsp';
		    	}
		    }
		});
	}
}

function comment_udpdate_init(el, idx){
	$("#editCommentIdx").val(idx);
	$("#comment-update").show().children("input").val($(el).closest(".comment").find(".comment-content").data("content")).focus();
	$("#comment-write").hide();
}

function comment_update(obj){
	var data = "comment_idx="+$("#editCommentIdx").val()+"&content="+$(obj).val();
	$.ajax({
		type : "post"
	    , url : "/commentUpdate"
	   	, data : data
	    , dataType : "text"
	    , timeout : 5000
	    , error : function() {
	    	alertShow("danger","다시 시도해 주세요", 2000);
	    	$(obj).removeAttr("disabled","disabled");
	    }
	    , success : function(response) {
	    	if(response == "execute"){
	    		$("#item-commentList > .comment").each(function(){
	    			if($(this).data("idx") == $("#editCommentIdx").val()){
	    				$(this).children(".comment-info").children(".comment-content").data("content", obj.value).html(obj.value);
			    		$("#comment-update").hide();
			    		$("#comment-write").show();
			    		alertShow("success","수정되었습니다", 2000);
			    		return false;
	    			}
		    	});
	    	}else if(response == "fail"){
	    		alertShow("danger","다시 시도해주세요", 2000);
	    	}else{
	    		location.href='/warning.jsp';
	    	}
	    }
	    , beforeSend: function() {
	    	$(obj).attr("disabled","disabled");
	    }
	    , complete: function() {
	    	$(obj).removeAttr("disabled","disabled");
	    }
	});
}

function commentReply(id){
	var inputComment = $("#inputComment");
	inputComment.val("@"+id+" ");
	var strLength= inputComment.val().length;
	inputComment.focus();
	inputComment[0].setSelectionRange(strLength, strLength);
	$("#comment-type").val("reply");
}

$("body").tooltip({
    selector: '[data-toggle="tooltip"]',
    'container': 'body'
});

$(document).on("click", "[data-target='post']", function(e){
	if($(window).innerWidth() > 1040){
		if(history.pushState) {
			$.getJSON(this.href).success(drawPost).error(requestError);
			return false;
		}
	}
	return true;
});

$(window).bind("popstate", function(event){
	var data = event.originalEvent.state;
	if (data){
		drawPost(data, false);
	}else{
		document.title = "Faeple";
		$("#post-modal").hide();
		$("#post-backdrop").fadeOut();
		$("body").removeClass("modal-open");
	}
});
	
function postImageLoaded(obj){
	$('div.post-imagebox').css('height',$(obj).height());
}

function drawPost(data, state){
	if(state){
		history.pushState(data, data.title, "/p/"+data.url);
		document.title = data.title;
	}
	$("#post-backdrop").show();
	$("#post-modal").show();
	$("body").addClass("modal-open");
	comment_cnt = data.comment_cnt;
	commentIndex = 0;
	post_idx = data.idx;
	post_memberIdx = data.member_idx;
	var imgLength = 0;
	
	var html = "<div class='post-imagebox'><div id='mySwipe' style='width:100%;' class='swipe'><div class='swipe-wrap'>";
	for(var i=1;i<9;i++){
		if(eval("data.image"+i) != null){
			if(eval("data.image"+i).trim() != ""){
				imgLength++;
				if(i == 1){
					html += "<div><img src='/resources/upload/post/thumbnail/"+eval("data.image"+i)+"' onload='postImageLoaded(this)'></div>";
				}else{
					html += "<div><img src='/resources/upload/post/thumbnail/"+eval("data.image"+i)+"'></div>";
				}
			}
		}
	}
	html += "</div></div>";
	if(imgLength != 1) {
		html += "<div id='slide-arrow-left' style='padding-left: 15px; left:0;' class='slide-image-arrow' onclick='mySwipe.prev()'><span class='slide-arrow'><i class='fa fa-chevron-left'></i></span></div><div id='slide-arrow-right' style='right:0; padding-left: 10px;' class='slide-image-arrow' onclick='mySwipe.next()'><span class='slide-arrow'><i class='fa fa-chevron-right'></i></span></div><div style='position:absolute; bottom: 20px; width:100%; left:0; text-align:center;'><ol class='carousel-indicators' id='image-list'>";
		for(var j=0;j<imgLength;j++){
			if(j==0) html += "<li class='active' data-index='"+j+"'></li>";
			else html += "<li data-index='"+j+"'></li>";
			
		}
		html += "</ol></div>";
	}
	html += "</div><div class='post-subbox'><div id='content-wrapper'><div style='height:78px;padding: 12px;'><div style='width:46px; float:left;'><a href='/"+data.member_id+"' target='_blank'><img src='/resources/upload/profile/thumbnail/"+data.profileImage+"' style='width:46px;height:46px;border-radius:50%;'></a></div><div style='margin-left:60px;margin-top:1px;'><div><p style='margin-bottom:4px;font-size:16px;font-weight:bold;'><a href='/"+data.member_id+"' target='_blank' class='userLink' style='font-weight:bold;'>"+data.author+"</a><a href='/"+data.member_id+"' style='text-decoration: none; margin-left: 6px; color:#c8c8c8; font-size:14px; font-weight: normal;'>@"+data.member_id+"</a></p></div><div><p style='margin:0; color: #aaa; display: block; float:left; font-size: 12px;'>"+timeleft(data.create_date)+"</p><p style='float:right;'>";
	if(data.followState != "me"){
		if(data.followState == "unFollow"){
			html += "<button type='button' class='btn btn-default btn-sm' onclick='profile_follow(this, \"follow\", "+data.member_idx+");' title='팔로우' style='width: 70px;'>팔로우</button>";
		}else{
			html += "<button type='button' class='btn btn-success btn-sm' onclick='profile_follow(this, \"unfollow\", "+data.member_idx+");' title='팔로우' style='width: 70px;'><i class='fa fa-check'></i>&nbsp;팔로잉</button>";
		}
	}
	html += "</p></div></div></div>";
	html += "<div style='padding:12px; word-break: break-all;'><p>"+data.content.parseURL().parseHashtag().parseUsername().parseEmoji()+"</p></div>";
	/*try{
		if(data.tags.length != 0) html += "<div class='item-tag' style='padding:12px;'>";
		for(var e=0;e<data.tags.length;e++){
  			html += "<a target='_blank' href='/hashtag/"+data.tags[e].name.replace(/&/gi,"%26").replace(/\./g, "%2E")+"' title='#"+data.tags[e].name+"'>#"+data.tags[e].name+"</a>";
  		}
		html += "</div>";
	}catch(e){
		
	}*/
	if(data.source != "" && data.source != null){
		var link = data.source;
		if (data.source.indexOf("http://") !== 0) {
			link = "http://" + data.source;
        }
		if(data.group == "user"){
			html += "<div class='post-source'><span>출처 : <a href='"+link+"' target='_blank'>"+data.source+"</a></span></div>";
		}else{
			html += "<div class='post-source'><a href='http://faeple.com/statistics/buylink?p="+data.idx+"&m="+data.member_idx+"&url="+link+"' target='_blank' style='color:#CF5050;text-decoration:none;'><i class='ion-bag' style='font-size:16px;'></i>&nbsp;상품구매 바로가기</a></div>";
		}
	}
	
	html += "<div class='section-count'>";
	if(data.like_cnt == 0){
		html += "<span style='cursor:default;'>좋아요&nbsp;<strong class='like-cnt'>0</strong></span>&nbsp;&nbsp;";
	}else{
		html += "<span onclick='showLikeMember("+data.idx+")'>좋아요&nbsp;<strong class='like-cnt'>"+data.like_cnt+"</strong></span>&nbsp;&nbsp;";
	}
	html += "&nbsp;&nbsp;<span onclick='$(\"#inputComment\").focus();'>댓글&nbsp;<strong class='comment-cnt'>"+data.comment_cnt+"</strong></span></div><div class='section-button'>";
	if(data.likeState == "unlike"){
		html += "<button type='button' title='좋아요' onclick='post_like(this, "+data.idx+", "+data.member_idx+", \""+data.image1+"\", \""+data.url+"\")'><i class='fa fa-heart' style='font-size: 13px;'></i>&nbsp;좋아요</button>";
	}else{
		html += "<button type='button' title='좋아요' onclick='post_like(this, "+data.idx+", "+data.member_idx+", \""+data.image1+"\", \""+data.url+"\")' style='color:#cc2e35;'><i class='fa fa-heart' style='font-size: 13px;'></i>&nbsp;좋아요</button>";
	}
	html += "<button type='button' title='공유하기' onclick='post_share(\""+shareParse(data.content)+"\", \""+shareParse(data.title)+"\", \""+data.image1+"\", \""+data.url+"\");'><i class='icon ion-share' style='font-size: 18px;'></i>&nbsp;공유하기</button><div class='btn-group' style='vertical-align:top;'><button type='button' title='더보기' class='dropdown' data-toggle='dropdown'><i class='icon ion-more' style='font-size: 18px; cursor: pointer;'></i>&nbsp;더보기</button><ul class='dropdown-menu more-dropdown' style='left:20px;top:123%;min-width:140px;font-size:14px;'><li style='position: absolute; top: -16px; left: 14px;'><img src='/resources/img/arrow_small.png'></li><li><a href='"+location.href+"' style='color: #333; font-weight: bold;''>뷰어에서 보기</a></li><li><a href='javascript:;' onclick='report("+data.idx+", \"post\")' style='color: #cd2f2f; font-weight: bold;'>콘텐츠 신고</a></li></ul></div></div><div class='comment-wrapper'><div class='post_line'></div>";
	
	
	html += "<div style='max-height:370px;overflow-y:auto;padding-top:8px;'>";
	if(data.comment_cnt > 8){
		html += "<span onclick='getMoreComment(this);' style='font-size:13px;padding: 4px 0 12px 6px;;display:block;cursor:pointer;'><i class='ion-loading-c' style='display:none;color:#666;font-size:16px;'></i>&nbsp;이전 댓글 보기</span>";
	}
	html += "<div id='item-commentList'>";
	if(data.comment_cnt != 0){
		loadComment_cnt = 0;
		for(var k=data.comment.length-1;k>-1;k--){
			html += "<div class='comment' data-idx='"+data.comment[k].idx+"' data-memidx='"+data.comment[k].member_idx+"'><div class='profile-img'><a href='/"+data.comment[k].member_id+"'><img src='/resources/upload/profile/thumbnail/"+data.comment[k].profileImage+"'></a></div><div class='comment-info'><span class='comment-author'><a class='userLink' style='font-weight:bold;' href='/"+data.comment[k].member_id+"'>"+data.comment[k].author+"</a></span><span class='comment-time'>"+timeleft(data.comment[k].create_date)+"</span><div class='comment-content' data-content='"+data.comment[k].content+"'>"+data.comment[k].content.parseUsername().parseURL().parseEmoji()+"</div></div>";
			if(member_idx == data.comment[k].member_idx){
				html += "<div class='comment-edit dropdown' title='수정 및 삭제' data-toggle='tooltip'><i class='glyphicon glyphicon-pencil comment-edit-btn' data-toggle='dropdown' data-container='body'></i><input type='hidden' id='editCommentIdx'><ul class='dropdown-menu cmt-dropdown' style='position:fixed;'><li onclick='comment_udpdate_init(this, "+data.comment[k].idx+")'>수정하기</li><li onclick='comment_del("+data.comment[k].idx+")' style='color:#cd2f2f;'>삭제하기</li></ul></div></div>";
			}else{
				html += "<div class='comment-report'><i class='fa fa-flag' data-toggle='tooltip' title='신고하기' onclick='report("+data.comment[k].idx+",\"comment\" )' /></div><div class='comment-reply'><i class='fa fa-reply' data-toggle='tooltip' title='답변하기' onclick='commentReply(\""+data.comment[k].member_id+"\")' /></div></div>";
			}
  			loadComment_cnt++;
  		}
	}
	html += "</div></div>";
	html += "<input type='hidden' id='comment-type' name='comment-type' value='default'>";
	html += "<div id='comment-write'><input id='inputComment' name='inputComment' maxlength='300' onkeypress='if (event.keyCode == 13) { submitComment(this, \""+data.image1+"\", \""+data.url+"\"); }' placeholder='댓글을 남겨보세요...'></input></div>";			
	html += "<div id='comment-update' title='취소하려면 esc키를 눌러주세요' data-toggle='tooltip'><input id='updateComment' name='updateComment' maxlength='300' onkeyup='if(event.keyCode == 13){ comment_update(this); }else if(event.keyCode == 27){ $(\"#comment-update\").hide(); $(\"#comment-write\").show(); }'></input></div></div><div id='like-member-wrapper' style='position:absolute;left:100%;top:0;width:100%;padding:12px;background-color:#fff;'><div style='text-align:center;position:relative;height:35px;border-bottom:1px solid #E4E4E4;'><button type='button' onclick='$(\"#content-wrapper\").removeClass(\"side\"); $(\".post-subbox\").css(\"height\", \"100%\");' style='position:absolute;top:-9px;left:0;font-size: 28px;color:#017AFC;border:0;background-color:#fff;'><i class='ion-arrow-left-c'></i></button><p>좋아하는 사람들</p></div><div id='likemember-list-loading' style='display: none;padding: 25px 0; text-align: center;'><img src='/resources/img/loading-20x20-white.gif'></div><ul id='likemember-list'></ul></div></div></div>";
	$("#post-viewer").html(html);
	
	var elem = document.getElementById("mySwipe");
	window.mySwipe = Swipe(elem, {
		callback: function(index, elem){
			$(".post-imagebox").css("height",$(elem).height());
			$("#image-list").children("li").each(function(){
				$(this).removeClass("active");
			});
			$("#image-list").children("li").siblings(":nth-child("+(index+1)+")").addClass("active");
		}
	});
}

function requestError(req, state) {
	alert("연결할 수 없습니다");
}

function post_like(button, post_idx, author_idx, refer_img, refer_url){
	if(!member_idx){
		alertShow("danger","로그인이 필요합니다", 2000);
	}else{
		var data = "post_idx="+post_idx+"&author_idx="+author_idx+"&refer_img="+refer_img+"&refer_url="+refer_url;
		var count = $(button).parent().prev().find(".like-cnt");
		var likeBtn = $("#itemList").find(".itembox[data-idx='"+post_idx+"']").find(".likeBtn");
		$.ajax({
	        type: "post",
	        url: "/addLike",
	        data: data,
	        dataType: "text",
	        timeout: 5000,
	        error: function () {
	            alertShow("danger", "다시 시도해주세요", 2000);
	        },
	        success: function (response) {
	            if (response == "unlike") {
	            	$(button).css("color", "#555");
	            	count.html(parseInt(count.html())-1);
	            	likeBtn.html("<i class='fa fa-heart'></i>")
	            	.parent().parent().parent().children("div.item-info").find("span.like_cnt").html(parseInt(likeBtn.parent().parent().parent().children("div.item-info").find("span.like_cnt").html())-1);
	            } else if (response == "execute") {
	            	$(button).css("color", "#cc2e35");
	            	count.html(parseInt(count.html())+1);
	            	likeBtn.html("<i class='fa fa-heart' style='color: #cc2e35;'></i>")
                	.parent().parent().parent().children("div.item-info").find("span.like_cnt").html(parseInt(likeBtn.parent().parent().parent().children("div.item-info").find("span.like_cnt").html())+1);
	            } else {
	                alert("잘못된 접근입니다");
	            }
	        }
	    });
	}
}

function profile_follow(obj, type, idx) {
	if(member_idx == ""){
		alertShow("danger", "로그인이 필요합니다", 2000);
	}else{
		var data = "following_idx="+idx;
		if(type == "follow") {
			$(obj).html("<div class='spinner small'></div>");
			setTimeout(function(){
				$.ajax({
					type: "post",
					url: "/follow",
					data: data,
					dataType: "text",
					timeout: 5000,
					error: function () {
                        alertShow("danger", "다시 시도해주세요", 2000);
                        $(obj).html("팔로우");
                    },
                    success: function (response) {
                        if (response == "success") {
                            $(obj).removeClass("btn-default").addClass("btn-success").html("<i class='fa fa-check'></i>&nbsp;팔로잉").attr("onclick", "profile_follow(this, 'unfollow', "+idx+");").hide().fadeIn();
                        }else if (response == "closed") {
                            alertShow("danger", "팔로우를 받지 않는 사용자입니다", 2000);
                        }else if (response == "role") {
                            alertShow("danger", "로그인이 필요합니다", 2000);
                        }else {
                            alertShow("danger", "다시 시도해주세요", 2000);
                        }
                    }
                });
           	},500);
		}else{
           	$(obj).html("<div class='spinner small'></div>");
           	setTimeout(function(){
           		$.ajax({
                    type: "post",
                    url: "/unFollow",
                    data: data,
                    dataType: "text",
                    timeout: 5000,
                    error: function () {
                        alertShow("danger", "다시 시도해주세요", 2000);
                        $(obj).html("<i class='fa fa-check'></i>&nbsp;팔로잉");
                    },
                    success: function (response) {
                        if (response == "fail") {
                            alertShow("danger", "다시 시도해주세요", 2000);
                        } else {
                            $(obj).removeAttr("data-state").removeClass("btn-success").addClass("btn-default").attr("onclick", "profile_follow(this, 'follow', "+idx+");").html("팔로우").hide().fadeIn();
                        }
                    }
                });
           	},500);
        }
	}
}

function showLikeMember(idx){
	$("#content-wrapper").addClass("side");
	$(".post-subbox").css("height",400);
	if($("#likemember-list").is(":empty")){
		$.ajax({
			type : "post"
		    , url : "/getPostLikeMemberList?post_idx="+idx+"&index="+likeMemberIndex+"&loadSize=40"
		    , dataType : "json"
		    , timeout : 5000
		  	, error : function() {
	  			$("#likemember-list").html("<li style='text-align:center;'>불러올 수 없습니다</li>");
		    }
		    , success : function(response) {
		    	var html = "";
		    	for(var i=0;i<response.length;i++){
		    		html += "<li><div><a href='/"+response[i].member_id+"' target='_blank'><img src='/resources/upload/profile/thumbnail/"+response[i].profileImage+"'></a></div><p><a target='_blank' class='lm-name' href='/"+response[i].member_id+"'>"+response[i].member_name+"</a><br><a target='_blank' class='lm-id' href='/"+response[i].member_id+"'>@"+response[i].member_id+"</a></p>";
		    		if(response[i].followState == "unFollow"){
		    			html += "<button type='button' class='btn btn-default btn-sm' onclick='profile_follow(this, \"follow\", "+response[i].member_idx+")'>팔로우</button></li>";
		    		}else if(response[i].followState == "following"){
		    			html += "<button type='button' class='btn btn-success btn-sm' onclick='profile_follow(this, \"unfollow\", "+response[i].member_idx+")'><i class='fa fa-check'></i>&nbsp;팔로잉</button></li>";
		    		}else{
		    			html += "</li>";
		    		}
		    	}
		    	$("#likemember-list").append(html);
		    	//$(".post-subbox").css("height",$("#like-member-wrapper").outerHeight());
		    }, beforeSend: function() {
		    	$("#likemember-list-loading").show();
		    }, complete : function(){
		    	$("#likemember-list-loading").hide();
		    }
		});
	}
}